﻿@{
    Layout = "~/Views/Shared/_level2.cshtml";
}
<title>系统管理-权限</title>
<link href="/SiteUI/Admin/share.css" rel="stylesheet" />
<link href="/SiteUI/Admin/Authority.css" rel="stylesheet" />

@section contentnavi{
    <div id="appTitle">
        系统管理
    </div>
<ul id="slideNavi">
    <li><a class="Lite" href="/Admin/Company"><i class="icon-qiyerenzheng"></i>企业信息<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Organize"><i class="icon-wangluo1"></i>组织架构<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Accounts"><i class="icon-accountbox"></i>员工账号<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Authority"><i class="icon-security"></i>权限设置<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/OpenApi"><i class="icon-swaphoriz"></i>开放接口<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Portal"><i class="icon-034library"></i>企业门户<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/CloudApp"><i class="icon-nowwidgets"></i>应用管理<i class="icon-navigatenext arrow-go"></i></a></li>
</ul>
}
<div class="col-lg-4" id="orgTree_wraper">
    <div class="row">

    </div>
</div>
<!--选定组织架构下的所有岗位-->
<div class="col-lg-8" id="orgPositions">
    <div class="row">
        <div class="FlateSectionHead">
            <h4><i class="icon-accountcircle"></i>岗位</h4>
        </div>
        <div class="col-lg-12" id="lstOrgPositions">

        </div>
    </div>
</div>
<div class="col-lg-8" id="posDetail">

</div>

<div style="display:none">
    <div class="row PosItem">
        <div class="col-lg-4 pi-name"></div>
        <div class="col-lg-8 pi-more">
            <div class="row">
                <div class="col-lg-12 pi-remark">

                </div>
            </div>
        </div>
    </div>
</div>
<script>
    Authority = {
        corg: {},
        tplPositionItem: null,
        lstPositions: null,
        onOrgSlcted: function (org) {
            Authority.corg = org;
            if (!org.positions) {
                //TODO:如果没有岗位信息，则异步加载
                Authority.lstPositions.Loading();
                pvOrganizeTree.GetOrgPositions(org.idstr, Authority.onGetPositionsEnd);
            }
            Authority.showOrgPositions();
        },
        showOrgPositions: function () {
            if (Authority.corg.positions) {
                Authority.lstPositions.vl(Authority.corg.positions)
                                     .update()
                                     .show();
            }
            else {
                Authority.lstPositions.vl(null)
                                     .Empty("没有设置岗位")
                                     .update()
                                     .show();
            }
        },
        onGetPositionsEnd: function (rtn) {
            //判断返回数据是否匹配当前选中的组织架构节点
            if (rtn.idstr == Authority.corg.idstr) {
                //TODO:刷新岗位列表
                Authority.showOrgPositions();
            }
        },
        onPosSlcted: function (ev, pos) {
            if (window.pvPositionDetail) {
                pvPositionDetail.LoadPosition(pos.idstr);
            }
            else {
                $("#posDetail").load("/Admin/pvPositionDetail.html", null, function () { pvPositionDetail.LoadPosition(pos.idstr); });
            }
        },
        _makePositionView: function ($cnt, pos) {
            var itm = Authority.tplPositionItem.clone();
            itm.children(".pi-name").vl(pos.name);
            itm.find(".pi-remark").vl(pos.remark);
            itm.data(pos);
            $cnt.append(itm);
        }
    }
    $(function () {
        $("body").on("UserReady", Authority.onUserReady);
        $("#orgTree_wraper>.row").load("/Admin/pvOrganizeTree.html", null, function () {
            if (window.pvOrganizeTree) {
                pvOrganizeTree.vf_onOrgSlcted = Authority.onOrgSlcted;
            }
        })
        var navis = $("#slideNavi>li>a");
        for (var i = 0; i < navis.length; i++) {
            if (navis.eq(i).attr("href") == window.location.pathname) {
                navis.eq(i).addClass("current");
                break;
            }
        }

        if (window.pvOrganizeTree) {
            pvOrganizeTree.vf_onOrgSlcted = Authority.onOrgSlcted;
        }
        Authority.tplPositionItem = $(".PosItem").eq(0);
        Authority.lstPositions = new LiberUI.Lister("#lstOrgPositions")
                                           .option("TreeMode", true)
                                           .option("NodePrefix", "-")
                                           .option("ContentRender", Authority._makePositionView)
                                           .Empty("请选择一个组织架构来查看")
                                           .on("itemSlcted", Authority.onPosSlcted);
    })
</script>
